import { createRouter, createWebHashHistory } from "vue-router";
//
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const routes = [
	{
		path: "/login",
		name: "login",
		component: () => import("../views/LoginView/index.vue"),
		meta: {
			title: "登录页",
		},
	},
	{
		path: "/file",
		name: "file",
		component: () => import("../Layout/index.vue"),
		meta: {
			title: "文件管理",
		},
		redirect: "/file/index",
		children: [
			{
				path: "index",
				component: () => import("../views/FileView/index.vue"),
				meta: {
					title: "文件列表",
				},
			},
		],
	},
	{
		path: "/watermark",
		name: "watermark",
		component: () => import("../Layout/index.vue"),
		meta: {
			title: "水印管理",
		},
		redirect: "/watermark/list",
		children: [
			{
				path: "list",
				component: () => import("../views/Watermark/list.vue"),
				meta: {
					title: "加水印管理列表",
				},
			},
			{
				path: "checklist",
				component: () => import("../views/Watermark/checklist.vue"),
				meta: {
					title: "水印检出处理列表",
				},
			},
		],
	},
	{
		path: "/setting",
		name: "setting",
		component: () => import("../Layout/index.vue"),
		meta: {
			title: "系统设置",
		},
		redirect: "/setting/usersetting",
		children: [
			{
				path: "userlist",
				component: () => import("../views/SettingView/userlist.vue"),
				meta: {
					title: "用户管理",
				},
			},
			{
				path: "updatepassword",
				component: () => import("../views/SettingView/updatepassword.vue"),
				meta: {
					title: "修改密码",
				},
			},
		],
	},
];

const router = createRouter({
	history: createWebHashHistory(),
	routes,
});

/*
 * 导航钩子
 * */
router.beforeEach((to, from, next) => {
	//开启进度条
	NProgress.start();
	next();
});

router.afterEach(() => {
	// 关闭进度条
	NProgress.done();
});

export default router;
